<?php

/**
 *
 * This page is used to redirect the browser from http://elgg.org/garrettn/page to the homepage
 *      for garrettn, usually http://elgg.org/garrettn/page/Homepage.
 *      It doesn't output any content, but redirects via headers.
 *         If the page hasn't been created yet, then redirects to Homepage\new
 *     Doesn't care about permissions.
 */

    require_once("../../../includes.php");
    require_once("../model/page.php");
    require_once("../model/user.php");

    // Retrieve page name & user name from url
    $username = folio_clean( required_param('user') );
    $url = url;

    // Load page
    $user = folio_user::SelectWhereUsername( $username );
    if ( !$user ) {
        trigger_error("Invalid username $username passed to homepage.php", E_USER_ERROR);
    }
    // set the current user.
    global $page_owner;
    $page_owner = $user->ident;


    $page = folio_page::SelectHomepage( $user );

    if( !$page ) {
        // Page not created, route to the 'new' page.

        header("Location: {$url}{$username}/page/home/Template");

        /*
        $body = '<p>' .
                __gettext('This homepage has not be created yet, but you can ') .
                "<a href='{$url}{$user->username}/page/Homepage/template'>" .
                __gettext('create one.') .
                "</a></p>";
        */


        //$body = __gettext('This user has not created a homepage.');
        //$body = '<p>' . $body . "</p>\n";

    } else {
        // Redirect to the homepage.
        header("Location: {$url}{$username}/page/" . folio_page::title_encode($page->title) );
    }

?>
